/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.review.dao;

import com.nus.dataaccess.dao.base.dao.BaseDao;
import com.nus.dataaccess.dao.review.ReviewAssignment;
import java.util.List;
import java.util.Map;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author robin.foe
 */
public class ReviewAssignmentDao extends BaseDao<ReviewAssignment>{
    
    private static ReviewAssignmentDao instance;

    public static ReviewAssignmentDao getInstance() {
        if (null == instance) {
            instance = new ReviewAssignmentDao();
        }
        return instance;
    }
    
    @Override
    protected Class getReferenceClass() {return ReviewAssignment.class;}
    
    public int getTotalCount(Map<String, Object> filters){
        Criteria crit = super.createCriteria();
        crit.setProjection(Projections.rowCount());
        if(filters!=null && !filters.isEmpty()){
            for(String key : filters.keySet() ){
                crit.add(Restrictions.eq(key, filters.get(key)));
            }
        }
        return ((Long)crit.list().get(0)).intValue();
    }
    
    public List<ReviewAssignment> paginate(int first, int pageSize, String sortField, boolean ascending, Map<String, Object> filters){
        Criteria crit = super.createCriteria();
        if(filters!=null && !filters.isEmpty()){
            for(String key : filters.keySet() ){
                crit.add(Restrictions.eq(key, filters.get(key)));
            }
        }
        
        crit.setFirstResult(first);
        crit.setMaxResults(pageSize);
        return crit.list();
    }
    
    
    
    
    
}
